def solution1(n):
    for i in range(n, 0, -1):
        for j in range(n, 0, -1):
            if j > i:  # 由此判断哪些需要打印，那些需要用空格填充
                print(' ' * len(str(j)), end=' ')
            else:
                print(j, end=' ')
        print()
    print('~~~~~~~~~~~~~')
    for i in range(1, n + 1):
        for j in range(n, 0, -1):
            if j > i:
                print(' ' * len(str(j)), end=' ')
            else:
                print(j, end=' ')
        print()


def solution2(n):
    num_list = [str(i) for i in range(n, 0, -1)]
    length = len(' '.join(num_list))  # 确定一个整长度
    for i in range(n, 0, -1):
        s = ' '.join(num_list[i - 1:])  # 此部分是需要显式打印的
        print(f'{s:>{length}} ')  # 打印length长度的字符串，靠右打印，用空白字符填充
    print('~~~~~~~~~~~~')

    for i in range(1, n + 1):
        s = ' '.join(num_list[i - 1:])
        print(f'{s:>{length}} ')


solution2(12)
